import { app, BrowserWindow, ipcMain, Menu } from 'electron'
import wallpaper from 'wallpaper'
import { resolve } from 'path'
import { downloadFile } from './uitl'

ipcMain.on('setWallpaper', async (_event: IpcMainEvent, url: string, path: string) => {
  console.log(url, path)
  const localFile = resolve(path, url.split('/').pop()||"")
  let file = await downloadFile(url, localFile)
  console.log(file)
  await wallpaper.set(file, { screen: 'all', scale: 'auto' }).catch((err) => {
    console.log(err)
  })
  // try {
  //  // const localFile = resolve(path, url.split('/').pop()!)
  //  // const file = await downloadFile(url, localFile)
  //  // 测试路径

  // } catch (error) {
  //   console.log(error)
  //   // dialog.showErrorBox('', '图片下载失败，请在设置中心定义目录')
  // }
})
